package com.googlecode.gwtbb.client.only.widget.form.entry;

import com.google.gwt.user.client.ui.*;
import com.googlecode.gwtbb.client.shared.validation.FieldId;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Abraham Grief
 * @version $Id$
 * @since Apr 30, 2008
 */
public abstract class SingleCellFormEntry extends FormEntryImpl implements HasHorizontalAlignment, HasVerticalAlignment {
	protected int row;
	protected int col;
	protected int rowSpan = 1;
	protected int colSpan = 1;
	protected HorizontalAlignmentConstant horizontalAlignment = ALIGN_CENTER;
	protected VerticalAlignmentConstant verticalAlignment = ALIGN_MIDDLE;
	private List widgetCells;

	public SingleCellFormEntry() {
	}

	public SingleCellFormEntry(FieldId fieldId, String defaultValue, int row, int col) {
		this.fieldId = fieldId;
		this.defaultValue = defaultValue;
		this.row = row;
		this.col = col;
	}

	public int getCol() {
		return col;
	}

	public void setCol(int col) {
		this.col = col;
	}

	public int getColSpan() {
		return colSpan;
	}

	public void setColSpan(int colSpan) {
		this.colSpan = colSpan;
	}

	public HorizontalAlignmentConstant getHorizontalAlignment() {
		return horizontalAlignment;
	}

	public void setHorizontalAlignment(HorizontalAlignmentConstant horizontalAlignment) {
		this.horizontalAlignment = horizontalAlignment;
	}

	public int getRow() {
		return row;
	}

	public void setRow(int row) {
		this.row = row;
	}

	public int getRowSpan() {
		return rowSpan;
	}

	public void setRowSpan(int rowSpan) {
		this.rowSpan = rowSpan;
	}

	public VerticalAlignmentConstant getVerticalAlignment() {
		return verticalAlignment;
	}

	public void setVerticalAlignment(VerticalAlignmentConstant verticalAlignment) {
		this.verticalAlignment = verticalAlignment;
	}

	public List<WidgetCell> getWidgetCells() {
		if (widgetCells == null) {
			widgetCells = new ArrayList(1);
			Panel wholeCell = new VerticalPanel();
			wholeCell.add(getFailurePanel());
			Widget widget = getEntryWidget();
			if (widget != null)
				wholeCell.add(widget);
			widgetCells.add(new WidgetCell(wholeCell, row, col, rowSpan, colSpan, horizontalAlignment, verticalAlignment));
		}
		return widgetCells;
	}
}
